<template>
  <el-container class="home" :style="'background-color:'+themeColor">
    <el-header
      class="header ub main-justify cross-center"
      :style="'background-color:'+backgroundColor"
    >
      <div class="head-title" style="font-size:30px">
        <img alt src="../assets/images/logo.png" class="logoimg" />
      </div>
      <div class="ub main-center cross-center header-right">
        <screenfull
          id="screenfull"
          class="right-menu-item hover-effect"
          @changeColor="changeColor"
        />
        <div>
          <el-dropdown placement="bottom-start">
            <img class="user-img" src="../assets/images/sub_account.png" alt />
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>个人中心</el-dropdown-item>
              <el-dropdown-item @click.native="logout()">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <div class="user-role">
          <div class="header-welcome">欢迎你，{{roleName}}</div>
          <div class="header-time">{{date}}</div>
        </div>
      </div>
    </el-header>

    <el-container>
      <el-aside width="auto">
        <menu-bar :color="BarColor"></menu-bar>
      </el-aside>
      <el-container>
        <el-main style="padding:0px">
          <i class="el-icon-s-fold arrow-icon" @click="arrowBtn"></i>
          <!-- <i class=" arrow-icon" @click="clearAllTabs" ></i> -->
          <el-button
            type="primary"
            @click="clearAllTabs"
            style="float: right;background-color:grey;border:none"
            icon="el-icon-delete"
          >关闭</el-button>
          <!-- <el-button type="primary" icon="el-icon-delete"></el-button> -->
          <tabs></tabs>
          <div id="apps">
            <!-- <keep-alive exclude="managerview,,customview,orderlist,clientlist">
              <router-view></router-view>
            </keep-alive> -->
              <router-view></router-view>

          </div>
        </el-main>

        <el-footer style="background-color: #2b2f3a;color:#fff;text-align:center">
          <span>&copy;版权由电子科技大学中山学院17级软件c班东软实训8组所有</span>
        </el-footer>
      </el-container>
    </el-container>
  </el-container>
</template>


<script>
var $vueIndex;
import tabs from "../components/tabs";
import MenuBar from "../components/MenuBar";
import Screenfull from "@/components/Screenfull";
export default {
  components: {
    tabs,
    MenuBar,
    Screenfull,
  },
  //要使用watch监听来判断路由是否有改变
  // watch: {
  //   $route(to, from) {
  //     //可以打印一下to 和 from 来看一下他们里面meta设置的index层级
  //     console.log(to, from);
  //     //判断进入的路由层级是否比要进入的路由层级大
  //     // if (to.meta.index > from.meta.index) {
  //     //   //设置动画名称
  //     //   this.animate = "slide-left";
  //     // } else {
  //     //   this.animate = "slide-right";
  //     // }
  //     this.animate = "slide-right";
  //   },
  // },
  // name: "home",
  data() {
    return {
      // backgroundColor:"#101010",
      BarColor: {
        barColor: "#101010",
        activeTextColor: "#38b8f4",
        textColor: "#fff",
      },
      themeColor: "#ffffff",
      backgroundColor: "#101010",
      animate: "",
      isCollapse: false,
      date: "",
      roleName: "",
    };
  },
  mounted() {
    $vueIndex = this;
    this.showTime();
    setInterval(function () {
      $vueIndex.showTime();
    }, 1000);
    this.setRoleName();
  },
  methods: {
    showTime() {
      var week = new Array(
        "星期日",
        "星期一",
        "星期二",
        "星期三",
        "星期四",
        "星期五",
        "星期六"
      );
      var date = new Date();
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      var hour = date.getHours();
      var minutes = date.getMinutes();
      var second = date.getSeconds();
      this.date =
        year +
        "." +
        (month < 10 ? "0" + month : month) +
        "." +
        day +
        "" +
        " " +
        hour +
        ":" +
        minutes +
        ":" +
        (second < 10 ? "0" + second : second) +
        " " +
        (week[date.getDay()] || "");
    },
    async logout() {
      const _this = this;

      let { data: res } = await this.$http.post("/api/user/loginOut");
      console.log(res);
      if (res.code == 200) {
        // this.$message.success(res.msg);
        _this.$message.success(res.msg);

        sessionStorage.clear();
        window.location.href = "/tologin";
      }
    },
    arrowBtn() {
      console.log("点击图标");
      this.$store.commit("setOpenOrClose");
    },
    setRoleName() {
      this.roleName = sessionStorage.getItem("roleName");
    },

    //清除所有tab
    clearAllTabs() {
      let obj = {};
      obj.lable = "首页";
      obj.name = "desktop";
      this.$store.commit("clearAllTabs");
      this.$store.commit("selectMenu", obj);
      this.$router.push({ name: obj.name });
    },
    changeColor() {
      this.BarColor = {
        barColor: "#101010",
        activeTextColor: "#38b8f4",
        textColor: "#fff",
      };
      // this.themeColor = this.themeColor==="#ffffff"?"#123123":"#ffffff";
      this.backgroundColor = this.backgroundColor==="#101010"?"#7171C6":"#101010";
    },
  },
};
</script>

<style  scoped>
.el-main/deep/.el-tabs__header {
  position: static !important;
}
.el-container .continer-main {
  height: 100%;
}
.home {
  height: 100%;
  /* background-color: "#7171C6"; */
  /* width: 100%; */
}
.home-container {
  height: 100%;
}
.head-right {
  margin-right: 30px;
}
.header {
  /* border: 1px solid red; */
  /* background-color: #101010; */
  color: #fff;
  height: 65px !important;
  padding: 0 0px;
}
.user-img {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  cursor: pointer;
}
.logoimg {
  height: 90px;
}

.el-aside {
  border-right: 1px solid #e6e6e6;
  background-color: #101010;
}

/* 此样式用于设置 el-aside width="auto" 宽度为auto的样式 */
.menu-bar:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}

.arrow-icon {
  float: left;
  background: #eaedf1;
  border: 1px solid transparent;
  font-size: 23px;
  height: 39px;
  line-height: 39px !important;
  width: 40px;
  text-align: center;
}
.user-role {
  margin-left: 10px;
  text-align: right;
}
.header-wellcome {
  font-size: 15px;
  font-weight: bolder;
}
.header-time {
  margin-top: 2px;
  font-size: 14px;
}
.header-right {
  margin-right: 30px;
}
/* html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
} */
</style>
